package com.cloudcc.frame.trigger;

import com.cloudcc.deveditor.trigger.TriggerEditor;
import com.cloudcc.frame.Utils.PushService;

public class notice_Test extends TriggerEditor {

    public void insert(){
        String name = record_new.get("companyName")==null?"":record_new.get("companyName")+"";
        String userId = record_new.get("accountId")==null?"":record_new.get("accountId")+"";
        String noticeInfo = record_new.get("noticeInfo")==null?"当前有新的开函通知，开函公司为":record_new.get("noticeInfo")+"";
        //   String type = record_new.get("type")==null?"":record_new.get("type")+"";

        PushService ps = new PushService(userInfo);

			/*
				消息分为英文（messageEN ）和中文（message ）
				消息参数说明 messageType为固定值notification（可显示在通知中心）
				function为固定值showmsg（手机端消息推送有新通知提示内容）
				relatedId为消息关联对象id,例如：某一个客户的id或联系人ID
				operatetype为自定义消息类型
				userid为接受推送用户ID
				contentText为推送消息内容
				reminderText为推送提示信息（目前没有用处）
			*/
        String operateType="newMsg";
        String contentText=noticeInfo+": "+name;
        String reminderText=noticeInfo+": "+name;
        String contentTextEN=noticeInfo+": "+name;
        String reminderTextEN=noticeInfo+": "+name;
        String message = "[{\"messageType\":\"notification\",\"function\":\"showmsg\",\"operatetype\":\""+operateType+"\",\"userid\":\""+userId+"\",\"relatedId\":\""+userId+"\",\"contentText\":\""+contentText+"\",\"reminderText\":\""+reminderText+"\"}]";
        String messageEN = "[{\"messageType\":\"notification\",\"function\":\"approval\",\"operatetype\":\""+operateType+"\",\"userid\":\""+userId+"\",\"relatedId\":\""+userId+"\",\"contentText\":\""+contentTextEN+"\",\"reminderText\":\""+reminderTextEN+"\"}]";
        //sendMessage参数依次为：接受推送用户ID，推送类型（为空）,中文消息，英文消息
        ps.sendMessage(userId,null,message ,messageEN);
    }
}
